package com.platform.core.service.impl;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.platform.comm.entity.IdEntity;
import com.platform.core.repository.SysConfRepository;
import com.platform.core.repository.SysConfTypeRepository;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Predicate;
import com.platform.comm.dto.DtoMapper;
import com.platform.comm.dto.KeyValue;
import com.platform.comm.enums.YnEnum;
import com.platform.comm.exceptions.RestApiException;
import com.platform.comm.util.TailCall;
import com.platform.comm.util.TailCalls;
import com.platform.comm.web.results.TreeNode;
import com.platform.core.entity.QSysConf;
import com.platform.core.entity.QSysConfType;
import com.platform.core.entity.SysConf;
import com.platform.core.entity.SysConfType;
import com.platform.core.service.SysConfTypeService;
import com.platform.dto.ConfQo;
import com.platform.dto.ConfTypeQo;
import com.platform.dto.ConfTypeTreeNode;
import com.platform.dto.CrClassifyDto;
import com.platform.dto.SysConfTypeDto;
import com.platform.enums.ConfValueMode;
import com.platform.utils.SysConfUtil;
import com.platform.utils.TreeNotRecursion;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QSort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;

import javax.persistence.EntityNotFoundException;
import java.util.*;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

import static com.platform.comm.constants.GlobalConstant.BASE_REDIS_CACHE_PREFIX;
import static com.platform.utils.SysConfUtil.DIR_CLASSIFY_CATE;

/**
 * Description: 类别信息-Service实现类
 *
 * @author libin Created on 2019/7/19
 **/
@Service
public class SysConfTypeServiceImpl extends BaseEntityBizImpl<SysConfTypeRepository, SysConfType> implements SysConfTypeService {
    private final QSysConfType qSysConfType = QSysConfType.sysConfType;
    private final QSysConf qSysConf = QSysConf.sysConf;
    private static final String ROUTE_SEPARATOR = "-";
    private final DtoMapper dtoMapper;
    private final SysConfRepository confRepository;
    private final String[] RES_TYPE_FILTER = {"重点人群", "荣誉信息", "金融信贷信息", "社会责任"};

    public SysConfTypeServiceImpl(SysConfTypeRepository baseRepository, DtoMapper dtoMapper, SysConfRepository confRepository) {
        super(baseRepository);
        this.dtoMapper = dtoMapper;
        this.confRepository = confRepository;
    }

    @Override
    public Map<String, String> getSystemInitInfo(String sys) {
        BooleanBuilder builder = new BooleanBuilder();
        builder.and(qSysConfType.typeCode.eq(sys));
        builder.and(qSysConfType.route.like("clz-conf%"));
        builder.and(qSysConfType.parentId.eq("pre_ncloud_sys_conf_type_11000"));
        builder.and(qSysConfType.delFlag.eq(YnEnum.N));
        SysConfType sysConfType = repository.findOne(builder).orElse(null);
        Map<String, String> map = Maps.newHashMap();
        if (Objects.nonNull(sysConfType)) {
            String typeId = sysConfType.getId();
            Iterable<SysConf> all = confRepository.findAll(qSysConf.typeId.eq(typeId));
            List<ConfQo> collect = StreamSupport.stream(all.spliterator(), false).map(entity -> dtoMapper.map(entity, ConfQo.class))
                    .collect(Collectors.toList());
            collect.forEach(item -> {
                if (Objects.nonNull(item.getValueMode()) && !ConfValueMode.InMulti.equals(item.getValueMode())) {
//                    ObjectNode confValue = item.getConfValue();
//                    String value = confValue.findValuesAsText(SysConfUtil.VALUE).get(0);
//                    map.put(item.getConfCode(), value);
                }
            });
        }
        return map;
    }

    @CacheEvict(value = BASE_REDIS_CACHE_PREFIX + "confType", allEntries = true)
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public ConfTypeQo create(ConfTypeQo confTypeQo) {
        if (confTypeQo.getTypeCode().contains("-")) {
            throw new RestApiException("类别编码包含非法字符'-'");
        }
        confTypeQo.init();
        SysConfType entity = dtoMapper.map(confTypeQo, SysConfType.class);
        // 设置route
        if (Strings.isNullOrEmpty(confTypeQo.getParentId())) {
            entity.setLevel(1);
            entity.setRoute(confTypeQo.getTypeCode());
        } else {
            SysConfType parent = fetchById(confTypeQo.getParentId());
            entity.setRoute(parent.getRoute() + ROUTE_SEPARATOR + confTypeQo.getTypeCode());
            entity.setLevel(parent.getLevel() + 1);
        }
        saveEntity(entity);
        return dtoMapper.map(entity, ConfTypeQo.class);
    }

    @CacheEvict(value = BASE_REDIS_CACHE_PREFIX + "confType", allEntries = true)
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public ConfTypeQo modify(ConfTypeQo confTypeQo) {
        if (confTypeQo.getTypeCode().contains("-")) {
            throw new RestApiException("类别编码包含非法字符'-'");
        }
        SysConfType entity = fetchById(confTypeQo.getId());
        if (Objects.equals(confTypeQo.getTypeCode(), entity.getTypeCode())) {
            dtoMapper.map(confTypeQo, entity);
            saveEntity(entity);
            return dtoMapper.map(entity, ConfTypeQo.class);
        }
        //如果修改了类别编码，则需要1.修改路由编码 2.修改该类别下的子类别的路由编码
        dtoMapper.map(confTypeQo, entity);
        String oldRouteCode = entity.getRoute();
        String newRouteCode = getParentRouteCode(entity) + "-" + confTypeQo.getTypeCode();
        updateChildRouteCode(newRouteCode, oldRouteCode);
        return dtoMapper.map(entity, ConfTypeQo.class);
    }

    /**
     * 获取父类的routeCode
     */
    public String getParentRouteCode(SysConfType entity) {
        SysConfType parentEntity = fetchById(entity.getParentId());
        return parentEntity.getRoute();
    }

    /**
     * 使用like查询，自身和子类别同时更新
     *
     * @param newCode 新的路由code
     * @param oldCode 旧的路由code
     */
    public void updateChildRouteCode(String newCode, String oldCode) {
        BooleanBuilder builder = new BooleanBuilder(qSysConfType.delFlag.eq(YnEnum.N));
        builder.and(qSysConfType.route.like(oldCode + "%"));
        Iterable<SysConfType> all = repository.findAll(builder);
        all.forEach(sysConfType -> {
            String route = sysConfType.getRoute();
            String s = route.replaceAll(oldCode, newCode);
            sysConfType.setRoute(s);
            saveEntity(sysConfType);
        });
    }

    @Override
    public ConfTypeQo getDetailByCode(String typeCode) {
        SysConfType sysConfType = queryOne(qSysConfType.typeCode.eq(typeCode)).orElse(null);
        return dtoMapper.map(sysConfType, ConfTypeQo.class);
    }

    @Override
    public ConfTypeQo getDetailByRouteCode(String routeCode) {
        SysConfType sysConfType = fetchOne(qSysConfType.route.eq(routeCode));
        return dtoMapper.map(sysConfType, ConfTypeQo.class);
    }

    @Override
    public String getNameByCode(String typeCode) {
        return Optional.ofNullable(this.getDetailByCode(typeCode)).map(ConfTypeQo::getTypeName).orElse(null);
    }

    @Override
    public String getNameByRouteCode(String routeCode) {
        return Optional.ofNullable(this.getDetailByRouteCode(routeCode)).map(ConfTypeQo::getTypeName).orElse(null);
    }


    @Override
    public List<SysConfTypeDto> queryResourceCate() {
        BooleanBuilder booleanBuilder = new BooleanBuilder();
        booleanBuilder.and(QSysConfType.sysConfType.route.like(DIR_CLASSIFY_CATE + "%")
                        .and(QSysConfType.sysConfType.level.eq(4)))
                .and(QSysConfType.sysConfType.typeName.notIn(RES_TYPE_FILTER));
        return this.queryAll(booleanBuilder, QSort.by(QSysConfType.sysConfType.sortNum.asc()))
                .stream().map(entity -> dtoMapper.map(entity, SysConfTypeDto.class)).collect(Collectors.toList());
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public SysConfTypeDto lock(Map<String, String> map) {
        Optional<SysConfType> sys = repository.findById(map.get("id"));
        SysConfType sysConfType = sys.orElseThrow(() -> new EntityNotFoundException("未能查询到相关的记录"));
//        if (Objects.isNull(sysConfType.getLock()) || sysConfType.getLock() != 1) {
//            sysConfType.setLock(1);
//        } else {
//            sysConfType.setLock(0);
//        }
        return dtoMapper.map(repository.save(sysConfType), SysConfTypeDto.class);
    }

    @Override
    public Page<ConfTypeQo> queryConfTypes(Predicate predicate, Pageable pageable, MultiValueMap<String, String> parameters) {
        String isCascade = parameters.getFirst("ifCascade");
        BooleanBuilder builder = new BooleanBuilder();
        if (StringUtils.isNotEmpty(isCascade) && "1".equals(isCascade)) {
            String typeCode = parameters.getFirst("typeCode");
            String typeName = parameters.getFirst("typeName");
            SysConfType root = fetchOne(qSysConfType.typeCode.eq(Objects.toString(typeCode, "hydm"))
                    .and(qSysConfType.delFlag.eq(YnEnum.N)));
            builder.and(qSysConfType.route.like(String.format("%s%%", root.getRoute())).and(qSysConfType.delFlag.eq(YnEnum.N)));
            if (StringUtils.isNotEmpty(typeName)) {
                builder.and(qSysConfType.typeName.like("%" + typeName + "%"));
            }
        } else {
            builder = new BooleanBuilder(predicate);
            String typeCode = parameters.getFirst("typeCode");
            if (StringUtils.isNotBlank(typeCode)) {
                builder.and(qSysConfType.typeCode.eq(typeCode));
            }
            String typeName = parameters.getFirst("typeName");
            if (StringUtils.isNotBlank(typeName)) {
                builder.and(qSysConfType.typeName.contains(typeName));
            }
            builder.and(qSysConfType.parentId.eq(parameters.getFirst("parentId")));
            builder = builderConditions(builder, parameters, SysConfType.class, qSysConfType.getMetadata());
        }
        Page<SysConfType> page = queryByPage(builder, pageable, jpqlQuery -> jpqlQuery.orderBy(qSysConfType.sortNum.asc()));
        return page.map(entity -> dtoMapper.map(entity, ConfTypeQo.class));
    }

    @CacheEvict(value = BASE_REDIS_CACHE_PREFIX + "confType", allEntries = true)
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public void changeDelFlag(List<String> ids, YnEnum ynEnum) {
        ids.stream().map(this::fetchById)
                .forEach(sysDepart -> sysDepart.setDelFlag(ynEnum));
        repository.flush();
    }

    @CacheEvict(value = BASE_REDIS_CACHE_PREFIX + "confType", allEntries = true)
    @Transactional(rollbackFor = {Exception.class})
    @Override
    public void remove(String id) {
        delete(id);
    }

    @Override
    public void delete(String id) {
        preDelete(id);
        repository.deleteById(id);
    }

    private void preDelete(String typeId) {
        // 物理删除时需要判断是否有子节点
        long count = repository.count(qSysConfType.parentId.eq(typeId));
        if (count > 0) {
            throw new RestApiException("包含子节点，不能删除");
        }
        // 判断该参数类别是否被参数设置引用
        long confCount = this.confRepository.count(qSysConf.typeId.eq(typeId));
        if (confCount > 0) {
            throw new RestApiException("该数据已经在参数设置中被引用，不能删除");
        }

    }

    @Override
    public long checkTypeCode(String id, String typeCode, String parentId) {
        BooleanBuilder builder = buildValidConditions(id);
        builder.and(qSysConfType.typeCode.eq(typeCode));
        builder.and(qSysConfType.parentId.eq(parentId));
        return repository.count(builder);
    }

    @Override
    public long checkTypeName(String id, String typeName, String parentId) {
        BooleanBuilder builder = buildValidConditions(id);
        builder.and(qSysConfType.typeName.eq(typeName));
        builder.and(qSysConfType.parentId.eq(parentId));
        return repository.count(builder);
    }

    private BooleanBuilder buildValidConditions(String id) {
        BooleanBuilder builder = new BooleanBuilder();
        if (!Strings.isNullOrEmpty(id)) {
            builder.and(qSysConfType.id.ne(id));
        }
        return builder;
    }

    @Override
    public List<ConfTypeTreeNode> treeByRouteCodeNotRecursion(String routeCode, boolean showHead, int showLevel) {
        List<ConfTypeQo> originData = getOriginData(routeCode, showHead, showLevel, true);
        return TreeNotRecursion.transListToTreeNode(originData);
    }

    @Override
    public List<ConfTypeTreeNode> treeByRouteCodeNotRecursionLowcode(String routeCode, boolean showHead, int showLevel){
        List<ConfTypeQo> originData = getOriginData(routeCode, showHead, showLevel, true);
        List<ConfTypeQo> filtedOriginData = originData.stream()
                .filter(type -> type.getRoute().equals(routeCode+"-system") || type.getRoute().equals(routeCode +"-app"))
                .collect(Collectors.toList());
        return TreeNotRecursion.transListToTreeNode(filtedOriginData);

    }

    @Override
    public List<ConfTypeQo> treeByLevel(String routeCode, int showLevel) {
        return getOriginData(routeCode, true, showLevel, false);
    }

    @Override
    public List<ConfTypeTreeNode> treeWithRouteCode(String routeCode, boolean showHead, int showLevel) {
        List<ConfTypeQo> originData = getOriginData(routeCode, showHead, showLevel, true);
        return TreeNotRecursion.transListToTreeNodeWithRouteCode(originData);
    }

    public List<ConfTypeQo> getOriginData(String routeCode, boolean showHead, int showLevel, boolean isTree) {
        BooleanBuilder builder = new BooleanBuilder(qSysConfType.delFlag.eq(YnEnum.N));
        Integer level = 0;
        if (!Strings.isNullOrEmpty(routeCode)) {
            //获取routeCode路由
            BooleanBuilder builder1 = new BooleanBuilder();
            builder1.and(qSysConfType.route.eq(routeCode));
            Optional<SysConfType> sysConfType = queryOne(builder1);
            if (sysConfType.isPresent()) {
                level = sysConfType.get().getLevel();
            }
        } else {
            routeCode = "clz";
        }
        //是否展示根结点
        if (!showHead) {
            routeCode = routeCode + "-";
        }
        //展示层级
        if (showLevel != -1) {
            if (isTree) {
                showLevel = showLevel + level;
                builder.and(qSysConfType.level.loe(showLevel));
            } else {
                builder.and(qSysConfType.level.eq(showLevel));
            }
        }
        builder.and(qSysConfType.route.like(routeCode + "%"));
        return queryAll(builder, QSort.by(qSysConfType.sortNum.asc()))
                .stream()
                .map(entity -> dtoMapper.map(entity, ConfTypeQo.class))
                .collect(Collectors.toList());
    }


    @Override
    public List<TreeNode> templateTree(String typeCodes) {
        String[] typeCodeArray = typeCodes.split(":");
        List<TreeNode> listNode = new ArrayList<>();
        for (String typeCode : typeCodeArray) {
            List<TreeNode> collect = StreamSupport.stream(
                            repository.findAll(qSysConfType.delFlag.eq(YnEnum.N).and(qSysConfType.typeCode.eq(typeCode)),
                                    QSort.by(qSysConfType.sortNum.asc())).spliterator(), false)
                    .map(this::toTreeNode).collect(Collectors.toList());
            listNode.addAll(collect);
        }
        return listNode;
    }

    private TreeNode toTreeNode(SysConfType sysConfType) {
        return TreeNode.of(sysConfType.getId(), sysConfType.getTypeCode(), sysConfType.getTypeName(),
                recursive(sysConfType.getId()));
    }

    private List<TreeNode> recursive(String parentId) {
        return StreamSupport.stream(repository.findAll(qSysConfType.parentId.eq(parentId)
                                .and(qSysConfType.delFlag.eq(YnEnum.N)),
                        QSort.by(qSysConfType.sortNum.asc())).spliterator(), true)
                .map(this::toTreeNode).collect(Collectors.toList());
    }

    @Override
    public List<String> queryChildrenTypeCodes(String typeCode) {
        BooleanBuilder builder = new BooleanBuilder(qSysConfType.delFlag.eq(YnEnum.N));
        if (!Strings.isNullOrEmpty(typeCode)) {
            builder.and(qSysConfType.typeCode.eq(typeCode));
        } else {
            builder.and(qSysConfType.parentId.isNull());
        }
        List<SysConfType> list = repository.findAll(builder, jpqlQuery -> jpqlQuery.orderBy(qSysConfType.sortNum.asc()));
        return tailRecursion(new ArrayList<>(),
                list,
                this::queryChildren).invoke();
    }

    private List<SysConfType> queryChildren(List<SysConfType> parents) {

        return repository.findAll(
                qSysConfType.parentId.in(parents.stream().map(IdEntity::getId).collect(Collectors.toList()))
                        .and(qSysConfType.delFlag.eq(YnEnum.N)),
                jpqlQuery -> jpqlQuery.orderBy(qSysConfType.sortNum.asc()));
    }

    /**
     * 使用尾递归接口完成
     *
     * @param list    当前递归栈的结果值
     * @param parents 下一个递归需要计算的值
     * @return 尾递归接口, 调用invoke启动及早求值获得结果
     */
    public TailCall<List<String>> tailRecursion(final List<String> list, final List<SysConfType> parents,
                                                UnaryOperator<List<SysConfType>> handle) {
        if (CollectionUtils.isEmpty(parents)) {
            return TailCalls.done(list);
        } else {
            list.addAll(parents.stream().map(SysConfType::getTypeCode).collect(Collectors.toList()));
            return TailCalls.call(() -> tailRecursion(list, handle.apply(parents), this::queryChildren));
        }
    }

    @Override
    public Map<String, String> queryAllApiCls(String typeCode) {
        Map<String, String> retMap = Maps.newLinkedHashMap();
        queryListResult(typeCode).forEach(entity -> retMap.put(entity.getTypeCode(), entity.getTypeName()));
        return retMap;
    }

    @Override
    public List<String> getHydmAndRegionValue(String typeCode) {
        String hydm = "HYDM_SELECT";
        List<SysConfType> sysConfTypes;
        if (hydm.equals(typeCode)) {
            sysConfTypes = queryListResult("hydm");
            return sysConfTypes.stream()
                    .filter(conf -> !conf.getLevel().equals(1) && !conf.getLevel().equals(2))
                    .map(SysConfType::getTypeName)
                    .collect(Collectors.toList());
        } else {
            sysConfTypes = queryListResult("region");
            return sysConfTypes.stream().map(SysConfType::getTypeName).collect(Collectors.toList());
        }
    }

    private List<SysConfType> queryListResult(String typeCode) {
        BooleanBuilder builder = new BooleanBuilder(qSysConfType.delFlag.eq(YnEnum.N));
        if (!Strings.isNullOrEmpty(typeCode)) {
            builder.and(qSysConfType.route.like(String.format("clz-%s%%", typeCode)));
        } else {
            builder.and(qSysConfType.route.like("clz%"));
        }
        return queryAll(builder, qSysConfType.level.asc(), qSysConfType.sortNum.asc());
    }

    @Override
    public List<Pair<String, String>> queryDirectSub(String typeCodes) {
        List<Pair<String, String>> retList = Lists.newArrayList();
        SysConfType sysConfType = repository.findOne(qSysConfType.typeCode.eq(typeCodes).and(qSysConfType.delFlag.eq(YnEnum.N)))
                .orElseThrow(() -> new RuntimeException("查询的类型不存在"));
        repository.findAll(qSysConfType.parentId.eq(sysConfType.getId()).and(qSysConfType.delFlag.eq(YnEnum.N)))
                .forEach(conf -> {
                    Pair<String, String> tPair = Pair.of(conf.getTypeCode(), conf.getTypeName());
                    retList.add(tPair);
                });
        return retList;
    }

    @Override
    public List<String> queryChildrenCodesNotRecursion(String typeCode) {
        SysConfType sysConfType = repository.findOne(qSysConfType.typeCode.eq(typeCode).and(qSysConfType.delFlag.eq(YnEnum.N)))
                .orElseThrow(() -> new RuntimeException("查询的类型不存在"));
        return queryAll(qSysConfType.route.like(String.format("%s%%", sysConfType.getRoute())).and(qSysConfType.delFlag.eq(YnEnum.N)))
                .stream()
                .map(SysConfType::getTypeCode)
                .collect(Collectors.toList());
    }

    @Override
    public List<KeyValue> bizMdFromDict(String code, String dictType) {
        SysConfType confType = fetchOne(qSysConfType.typeCode.eq(code));
        if (dictType.equals("1")) {
            return queryAll(qSysConfType.parentId.eq(confType.getId())).stream()
                    .map(item -> KeyValue.of(item.getTypeCode(), item.getTypeName())).collect(Collectors.toList());
        } else {
            return confRepository.findAll(qSysConf.typeId.eq(confType.getId()), jpqlQuery -> jpqlQuery.from(qSysConf)).stream()
                    .map(item -> KeyValue.of(item.getConfCode(), item.getConfName())).collect(Collectors.toList());
        }
    }

    @Override
    public Map<String, Map<String, String>> getClassifyMapByCode(List<String> codes) {
        Map<String, Map<String, String>> maps = Maps.newHashMap();
        codes.forEach(code -> {
            BooleanBuilder booleanBuilder = new BooleanBuilder(qSysConfType.route.eq(code));
            Optional<SysConfType> sysConfType = this.queryOne(booleanBuilder);
            Map<String, String> map = Maps.newHashMap();
            if (sysConfType.isPresent()) {
                SysConfType child = sysConfType.get();
                Optional<SysConfType> parentOptional = this.queryOne(qSysConfType.id.eq(child.getParentId()));
                if (parentOptional.isPresent()) {
                    SysConfType parent = parentOptional.get();
                    map.put(child.getTypeName(), SysConfUtil.DIR_CLASSIFY.equalsIgnoreCase(parent.getRoute()) ? "" : parent.getTypeName());
                } else {
                    map.put(child.getTypeName(), "");
                }
            }
            maps.put(code, map);
        });

        return maps;
    }

    @Override
    public CrClassifyDto getCrClassify() {
        List<String> cateArr = Arrays.asList("基础登记类", "运营及财务类", "司法信息", "行政执法信息", "社会评价类", "社会责任信息", "荣誉信息", "其他信息");
        List<SysConfTypeDto> cates = queryAll(qSysConfType.typeName.in(cateArr).and(qSysConfType.level.eq(4)), QSort.by(qSysConfType.sortNum.asc()))
                .stream().map(SysConfType::of).collect(Collectors.toList());
        List<SysConfTypeDto> subCates = queryAll(qSysConfType.parentId.in(cates.stream().map(SysConfTypeDto::getId)
                .collect(Collectors.toList())), QSort.by(qSysConfType.sortNum.asc())).stream().map(SysConfType::of).collect(Collectors.toList());
        return new CrClassifyDto(cates, subCates);
    }

    @Override
    public List<ConfTypeQo> getListByRouteCodeApi(String routeCode) {
        Optional<SysConfType> sysConfType = queryOne(qSysConfType.route.eq(routeCode).and(qSysConfType.delFlag.eq(YnEnum.N)));
        return sysConfType.map(confType -> this.repository.findAll(qSysConfType.parentId.eq(confType.getId()).and(qSysConfType.delFlag.eq(YnEnum.N)),
                        jpqlQuery -> jpqlQuery.orderBy(qSysConfType.sortNum.asc()))
                .stream().map(x -> dtoMapper.map(x, ConfTypeQo.class)).collect(Collectors.toList())).orElseGet(ArrayList::new);
    }


    @Override
    public void removeByRoute(ConfTypeQo confTypeQo) {
        if (StringUtils.isEmpty(confTypeQo.getRoute())) {
            return;
        }
        queryAll(qSysConfType.route.eq(confTypeQo.getRoute())).forEach(item -> {
            repository.deleteById(item.getId());
        });
    }


    @Override
    public List<ConfTypeQo> getListByLikeRouteCodeApi(String routeCode) {
        return queryAll(qSysConfType.route.startsWith(routeCode + "-").and(qSysConfType.delFlag.eq(YnEnum.N)))
                .stream().map(x -> dtoMapper.map(x, ConfTypeQo.class)).collect(Collectors.toList());
    }

}
